package com.ocean.web.controller.product;

import java.util.List;

import com.ocean.productDict.domain.OHistoryDays;
import com.ocean.productDict.service.IOHistoryDaysService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ocean.common.annotation.Log;
import com.ocean.common.enums.BusinessType;
import com.ocean.common.core.controller.BaseController;
import com.ocean.common.core.domain.AjaxResult;
import com.ocean.common.utils.poi.ExcelUtil;
import com.ocean.common.core.page.TableDataInfo;

/**
 * 历史天数维护Controller
 *
 * @author ocean
 * @date 2023-01-10
 */
@Controller
@RequestMapping("/product/historyDays")
public class OHistoryDaysController extends BaseController
{
    private String prefix = "product/historyDays";

    @Autowired
    private IOHistoryDaysService oHistoryDaysService;

    @RequiresPermissions("product:historyDays:view")
    @GetMapping()
    public String historyDays()
    {
        return prefix + "/historyDays";
    }

    /**
     * 查询历史天数维护列表
     */
    @RequiresPermissions("product:historyDays:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OHistoryDays oHistoryDays)
    {
        startPage();
        List<OHistoryDays> list = oHistoryDaysService.selectOHistoryDaysList(oHistoryDays);
        return getDataTable(list);
    }

    /**
     * 导出历史天数维护列表
     */
    @RequiresPermissions("product:historyDays:export")
    @Log(title = "历史天数维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OHistoryDays oHistoryDays)
    {
        List<OHistoryDays> list = oHistoryDaysService.selectOHistoryDaysList(oHistoryDays);
        ExcelUtil<OHistoryDays> util = new ExcelUtil<OHistoryDays>(OHistoryDays.class);
        return util.exportExcel(list, "历史天数维护数据");
    }

    /**
     * 新增历史天数维护
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存历史天数维护
     */
    @RequiresPermissions("product:historyDays:add")
    @Log(title = "历史天数维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OHistoryDays oHistoryDays)
    {
        return toAjax(oHistoryDaysService.insertOHistoryDays(oHistoryDays));
    }

    /**
     * 修改历史天数维护
     */
    @RequiresPermissions("product:historyDays:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        OHistoryDays oHistoryDays = oHistoryDaysService.selectOHistoryDaysById(id);
        mmap.put("oHistoryDays", oHistoryDays);
        return prefix + "/edit";
    }

    /**
     * 修改保存历史天数维护
     */
    @RequiresPermissions("product:historyDays:edit")
    @Log(title = "历史天数维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OHistoryDays oHistoryDays)
    {
        return toAjax(oHistoryDaysService.updateOHistoryDays(oHistoryDays));
    }

    /**
     * 删除历史天数维护
     */
    @RequiresPermissions("product:historyDays:remove")
    @Log(title = "历史天数维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(oHistoryDaysService.deleteOHistoryDaysByIds(ids));
    }
}
